package com.wtp.wallpaper.controller.user;

import com.wtp.wallpaper.annotation.ReplaceURL;
import com.wtp.wallpaper.pojo.entity.Classify;
import com.wtp.wallpaper.pojo.query.PageQuery;
import com.wtp.wallpaper.pojo.vo.ClassifyVO;
import com.wtp.wallpaper.pojo.result.Result;
import com.wtp.wallpaper.service.ClassifyService;
import com.wtp.wallpaper.utils.PojoConvertUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//@Api("分类相关接口")
@RestController
@Slf4j
public class ClassifyController {

    @Autowired
    private ClassifyService classifyService;

    //@ApiOperation("获取分类")
    @GetMapping("/classify")
    @ReplaceURL
    public Result getClassifyPage(PageQuery pageQuery){
        log.info("pageQuery:{}",pageQuery);
        List<Classify> records = classifyService.page(pageQuery.toMpPage("sort", true)).getRecords();
        return Result.success(PojoConvertUtil.convert(records, ClassifyVO.class));
    }

    //获取所有分类
    @GetMapping("/classifyList")
    public Result getClassifyList(){
        return Result.success(PojoConvertUtil.convert(classifyService.list(),ClassifyVO.class));
    }
}
